﻿package com.athena.controller 
{
	/**
	 * ...
	 * @author Tamnt
	 */
	import flash.display.*;
	import flash.text.TextFormat;
	import flash.events.*;
	import com.athena.vo.ObjectLevelRoom;
	
	public class LevelRoomController 
	{
		var movie_mc:MovieClip;
		var objLevel:ObjectLevelRoom;
		
		public function LevelRoomController(_mc:MovieClip, _obj:ObjectLevelRoom) 
		{
			movie_mc = _mc;
			objLevel = _obj;			
			/*if (objLevel.MinMark == 0) {
				movie_mc.header_txt.text = objLevel.LevelName 
												+ " (Từ " + numberFormat(objLevel.MinMark, 0, false, true) + " đến " + numberFormat(objLevel.MaxMark, 0, false,true) + " AG)";
			} else {
				movie_mc.header_txt.text = objLevel.LevelName 
												+ " (" + numberFormat(objLevel.MinMark, 0, false, true) + " AG trở lên)";
			}
			
			movie_mc.description_txt.text = "" ;// "Hiện có " 
												//+ objLevel.CurrPlayer 
												//+ " người chơi";
			var formatText : TextFormat = new TextFormat() ;				
			formatText.font = "Tahoma" ;
			formatText.bold = true ;
			formatText.size = 13 ;
			movie_mc.header_txt.setTextFormat(formatText) ;			
			movie_mc.btn_mc.arrow_mc.gotoAndStop(1);
			movie_mc.buttonMode = true;*/
			movie_mc.addEventListener(MouseEvent.MOUSE_OVER, movie_mc_over);
			movie_mc.addEventListener(MouseEvent.MOUSE_OUT, movie_mc_out);
			movie_mc.addEventListener(MouseEvent.CLICK, movie_mc_click);
			movie_mc.arrow_mc.gotoAndStop(1);
			movie_mc.buttonMode = true;
			
		}
		/******************************** Lam tron va hien thi so ***************************************/
		public static function numberFormat(number:Number, maxDecimals:int = 2, forceDecimals:Boolean = false, siStyle:Boolean = true):String {
			var i:int = 0, inc:Number = Math.pow(10, maxDecimals), str:String = String(Math.round(inc * Number(number))/inc);
			var hasSep:Boolean = str.indexOf(",") == -1, sep:int = hasSep ? str.length : str.indexOf(",");
			var ret:String = (hasSep && !forceDecimals ? "" : (siStyle ? "," : ".")) + str.substr(sep+1);
			if (forceDecimals) for (var j:int = 0; j <= maxDecimals - (str.length - (hasSep ? sep-1 : sep)); j++) ret += "0";
			while (i + 3 < (str.substr(0, 1) == "-" ? sep-1 : sep)) ret = (siStyle ? "," : ".") + str.substr(sep - (i += 3), 3) + ret;
			return str.substr(0, sep - i) + ret;
		}
		function movie_mc_over(evt:Event)
		{			
			movie_mc.arrow_mc.play() ;
		}
		
		function movie_mc_out(evt:Event)
		{
			movie_mc.arrow_mc.stop() ;
		}		

		function movie_mc_click(evt:Event)
		{
			Cotuong.currLevel = objLevel ;
			Cotuong.clickLevel(objLevel.LevelID, objLevel.MaxMark, objLevel.MinMark);			
		}
	}
}